#include <linux/module.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <linux/interrupt.h>
#include <linux/sched.h>




#define FS4412_LED2_ON  0x10
#define FS4412_LED2_OFF 0x20
#define FS4412_LED3_ON 0x13
#define FS4412_LED3_OFF 0x23

#define GPX2CON 0x11000c40
#define GPX2DAT 0x11000c44

#define GPX1CON 0x11000c20
#define GPX1DAT 0x11000c24


unsigned int *gpx2con_vir;
unsigned int *gpx2dat_vir;

unsigned int *gpx1con_vir;
unsigned int *gpx1dat_vir;


unsigned int major;
struct class *cls;

int fs4412_led_open (struct inode *inode, struct file *filp)
{
    printk("fs4412_led_open\n");
    return 0;
}
int fs4412_led_close(struct inode *inode, struct file *filp)
{
    printk("fs4412_led_close\n");
    return 0;
}


long fs4412_led_ioctl(struct file *filp, unsigned int cmd, unsigned long args)
{
    switch(cmd){
        case  FS4412_LED2_ON:
                        printk("fs4412 led2 on\n");
                        writel(0x80,gpx2dat_vir);
			  				
                        break;
        case FS4412_LED2_OFF:
                         printk("fs4412 led2 off\n");
                         writel(0x00,gpx2dat_vir);
			 			 break;
		 case  FS4412_LED3_ON:
                        printk("fs4412 led3 on\n");
                       	writel(0x01,gpx1dat_vir);	
                        break;
        case FS4412_LED3_OFF:
                         printk("fs4412 led3 off\n");
                         
			 			 writel(0x00,gpx1dat_vir);	
                      	 break;				 
        default:
                    break;

    }
    
    return 0;
}
   
struct file_operations fops = {
        .owner = THIS_MODULE,
        .open = fs4412_led_open,
        .release = fs4412_led_close,
        .unlocked_ioctl = fs4412_led_ioctl,
};

int fs4412_led_init(void)
{
    major = register_chrdev(0, "chr", &fops);
    printk("-----------%d------\n",major);
    cls = class_create(THIS_MODULE, "chrdev");
    device_create(cls, NULL, MKDEV(major,0), NULL, "led2");

	printk("create ok\n");

    gpx2con_vir = ioremap(GPX2CON, 4);
    gpx2dat_vir = ioremap(GPX2DAT, 4);
   writel(readl(gpx2con_vir) & ~(0xf << 28) | (0x1 << 28), gpx2con_vir);

   gpx1con_vir = ioremap(GPX1CON, 4);
   gpx1dat_vir = ioremap(GPX1DAT, 4);
   writel(readl(gpx1con_vir) & ~0xf | 0x1 , gpx1con_vir);
    
    return 0;
}


void fs4412_led_exit(void)
{
     printk("-----------%s------\n",__FUNCTION__);   
     device_destroy(cls, MKDEV(major,0));
     class_destroy(cls);
     unregister_chrdev(major, "chr");
}

module_init(fs4412_led_init);//加载时调入函数入口  初始化

module_exit(fs4412_led_exit);//卸载时调用函数出口释放

MODULE_LICENSE("GPL");//公共许可


